<?php
/**
 * Created by PhpStorm.
 * User: 会吃草的鱼
 * Date: 16/8/9
 * Time: 10:18
 */

namespace Recruit\Api;


use Common\Api\Api;
use Recruit\Model\UcenterMemberModel;

class UcenterMemberApi extends Api{
    /*
     * 取回一条数据 根据ID
     * */
    const GET_INFO = "Recruit/UcenterMember/getInfo";
    /*
     * 更新修改信息
     * */
    const SAVE = 'Recruit/UcenterMember/save';
    /*
     * 联合3张表进行学生信息查询
     * */
    const JOIN_AUTH_PAGE = "Recruit/UcenterMember/joinauthpage";

    /*
     * 联合2张表找出一条数据
     * */
    const JOIN_AUTH_GET = 'Recruit/UcenterMember/joinauthget';

    protected function _init(){
        $this->model = new UcenterMemberModel();
    }

    public function joinauthpage($map = null, $page = array('curpage'=>0,'size'=>10), $order = false, $params = false, $fields = false){

        $query = $this->model->join('JOIN common_member ON common_member.uid = itboye_ucenter_member.id')->join('JOIN common_auth_group_access ON common_auth_group_access.uid = itboye_ucenter_member.id')->join('LEFT JOIN itboye_user_resume ON itboye_ucenter_member.id = itboye_user_resume.uid');
        if(!is_null($map)){
            $query = $query->where($map);
        }

        if(!($order === false)){
            $query = $query->order($order);
        }

        if(!($fields === false)){
            $query = $query->field($fields);
        }
        $list = $query -> page($page['curpage'] . ',' . $page['size']) -> select();

        if ($list === false) {
            $error = $this -> model -> getDbError();
            return $this -> apiReturnErr($error);
        }

        $count = count($list);
        // 查询满足要求的总记录数
        $Page = new \Think\Page($count, $page['size']);

        //分页跳转的时候保证查询条件
        if ($params !== false) {
            foreach ($params as $key => $val) {
                $Page -> parameter[$key] = urlencode($val);
            }
        }

        // 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page -> show();

        return $this -> apiReturnSuc(array("show" => $show, "list" => $list));
    }


    /*
    * 联合2张表找出一条数据
    * */

    public function joinauthget($map = null, $order = false, $fields = false){
        $query = $this->model->join('JOIN common_member ON common_member.uid = itboye_ucenter_member.id');
        if(!is_null($map)){
            $query = $query->where($map);
        }

        if(!($order === false)){
            $query = $query->order($order);
        }
        if(!($fields === false)){
            $query = $query->field($fields);
        }
        $list = $query-> find();
        if ($list === false) {
            $error = $this -> model -> getDbError();
            return $this -> apiReturnErr($error);
        }
        return $this -> apiReturnSuc($list);
    }

}